<?php
/*
视频审核管理
*/
class VideoController extends MyClass_Action {
	protected $controller;
	protected $action;
	protected $_user;
	protected $_dbAdapter;
	
	public function init() {
		$this->commonAction();	

/*		$groupid = ( int ) $this->_request->getParam ( 'groupid' );
		if($groupid)
			$this->_dbAdapter=$this->getDbLink($groupid);
*/			
	}
	
	public function indexAction(){
		try {
			$sql="SELECT * FROM `groups`";
			$result=$this->_dbAdapter ->fetchAssoc ( $sql );
			$this->view->result=$result;
		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), 'note', 'javascript:window.history.back();', 'warning' );
		}
	}

	public function checkAction(){
		try {
			$groupid = ( int ) $this->_request->getParam ( 'groupid' );
	     	if (! $groupid)
				throw new Exception ( '参数错误！' );
			$this->view->groupid=$groupid;
			
			$sql="SELECT * FROM `groups` where groupid=".$groupid;
			$result = $this->_dbAdapter->fetchRow ($sql);
			$this->view->group= $result; 

			//取集团校区
			$sql="SELECT schoolid,schoolname FROM school where groupid=".$groupid." order by schoolid asc ";
			$school=$this->_dbAdapter->fetchAssoc ( $sql );
			$this->view->school= $school; 
			
			$sql="select schoolid,COUNT(articlefilesid) as number from article_files_class_v where groupid=".$groupid." and  isdelete=0 and ischecked=0 and mark=0 and fext='mp4' group by schoolid";
			$school_picture=$this->_dbAdapter->fetchAssoc($sql); 
			$this->view->school_picture=$school_picture;
			//print_r($school_picture);exit;
			$schoolid = ( int ) $this->_request->getParam ( 'schoolid' );
			$this->view->schoolid=$schoolid;
			
			if($schoolid){
				$sql="select from_unixtime(uploadtime,'%Y-%m-%d') as uploaddate,count(*) as num from article_files_class_v where groupid=".$groupid." and schoolid=".$schoolid." and isdelete=0 and ischecked=0 and fext='mp4' group by from_unixtime(uploadtime,'%Y-%m-%d') order by uploadtime desc ";
				$uploaddatelist=$this->_dbAdapter->fetchPairs($sql); 
				$this->view->uploaddatelist=$uploaddatelist;
				
				if($uploaddatelist){
					$uploaddate=$this->_request->getParam ( 'uploaddate' );
				$uploadkeys=array_keys($uploaddatelist);
				
				if(!$uploaddate || !in_array($uploaddate,$uploadkeys) )
					$uploaddate=current($uploadkeys);

				$this->view->uploaddate=$uploaddate;

				$sql="select articlefilesid,articlekey,concat('http://',cloudhost,cloudpath,cloudfilename,'.',fext) as avatar,intro,uid_class,memberlist,schoolid,classname,from_unixtime(uploadtime,'%Y-%m-%d %H:%i') as uploadtimeDisp from article_files_class_v where groupid=".$groupid." and schoolid=".$schoolid." and isdelete=0 and ischecked=0 and fext='mp4' and  from_unixtime(uploadtime,'%Y-%m-%d')='".$uploaddate."' ORDER BY uploadtimeDisp desc ";
			    $picturelist_tmp=$this->_dbAdapter->fetchAll($sql); 
				
				$picturelist=array();
				$this->view->list = $list = 3;
				foreach($picturelist_tmp as $key=>$value){
					$value['memberlist']=explode(',',$value['memberlist']);
					$mod=$key%$list;
					$picturelist[$mod][]=$value;
				}
				unset($picturelist_tmp);
				$this->view->picturelist=$picturelist;
				//print_r($picturelist);exit;
				}
			}
		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), 'note', 'javascript:window.history.back();', 'warning' );
		}
	}

	public function showvideoAction(){
		try {
			$groupid = ( int ) $this->_request->getParam ( 'groupid' );
			$articlefilesid = $this->_request->getParam ( 'articlefilesid' );
			$schoolid = $this->_request->getParam ( 'schoolid' );
			//print_r($groupid);echo '<br />';print_r($schoolid);echo '<br />';print_r($articlefilesid);exit;

	     	if (! $groupid)
				throw new Exception ( '参数错误！' );
	     	if (! $articlefilesid)
				throw new Exception ( '参数错误！' );
	     	if (! $schoolid)
				throw new Exception ( '参数错误！' );
			$this->view->groupid=$groupid;
			$this->view->schoolid=$schoolid;
						
			if($schoolid){
				$sql="select concat('http://',cloudhost,cloudpath,cloudfilename,'.',fext) as avatar,intro from article_files where groupid=".$groupid." and articlefilesid='".$articlefilesid."'";
				//echo $sql;exit;
			    $picturelist=$this->_dbAdapter->fetchRow($sql); 
				$this->view->picturelist=$picturelist;
				//print_r($picturelist);exit;
			}
		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), 'note', 'javascript:window.history.back();', 'warning' );
		}
	}

/*
处理审核视频
*/
	public function operatecheckedAction(){
		try {
			if (! $this->isPost ()) {
				throw new Exception ( '参数错误' );
			}
			$p =$this->_request->getPost ();
			//print_r($p);exit;
			//Array ( [check] => Array ( [2968] => 1 ) [uploaddate] => 2014-01-14 [pid] => 2 [sid] => 57 ) 
			$schoolid=$p['sid'];
			$uploaddate=$p['uploaddate'];
			$groupid=$p['pid'];
			if(!$groupid)
				throw new Exception ( 'groupid 错误！' );
				
			$sql="SELECT * FROM `groups` where groupid=".$groupid;
			$result = $this->_dbAdapter->fetchRow ($sql);
			
/*			if($groupid)
				$this->_dbAdapter=$this->getDbLink($groupid);
*/
			$isok_check=0;
			$isok_del=0;
			$publish=array();
			foreach($p['check'] as $key=>$value){
				if(!$value)
					continue;
				if($value==1){
					$array=array('ischecked'=>1);
					$publish[]=$key;
				}elseif($value==3){
					$array=array('isdelete'=>1);
				}

				$result = $this->_dbAdapter->update('article_files',$array, "groupid=".$groupid." and articlefilesid='".$key."'");
				if($result){
					if($value==1)
						$isok_check++;
					elseif ($value==3){
						$isok_del++;
					}
				}
			}
			//print_r($publish);exit;
			$isok_work=0;
			if(isset($p['works']) && is_array($p['works'])){
				foreach($p['works'] as $key=>$value){
					$result = $this->_dbAdapter->update('article_files',$array=array('mark'=>1), "groupid=".$groupid." and  articlefilesid='".$value."'");
					if($result)
						$isok_work++;

				}
			}
/***************************************************************************/
			
			if($publish){	
				//取采用照片积分标准
				$sql="SELECT value FROM `setting` where variable='credit_artice_photo'";
				$credit_artice_photo = $this->_dbAdapter->fetchOne ($sql);
				
				//取发送对象
				$isok_publish=0;
				foreach($publish as $key=>$value){
					$sql='select * from article_files where groupid='.$groupid.' and articlefilesid='.$value;
					$res = $this->_dbAdapter->fetchRow($sql);
					
					if($res['memberlist']<>0){
						$studentlist=explode(',',$res['memberlist']);
					}
					//print_r($studentlist);echo '<br />';
					$stu_name=array();
					foreach($studentlist as $key1=>$value1){
						if(!in_array($value1,$stu_name)){
							$stu_name[]=$value1;
						}else{
							continue;
						}
					}
					//print_r($stu_name);exit;
					$data=array();
					$t=$res['uploadtime'];
					$data=array(
						'content'=>$res['intro'],
						'createteacherid'=>$res['uid_class'],
						'classid'=>$res['uid_class'],
						'title'=>$res['intro'],
						'addtime'=>$t,
						'publishteacherid'=>$res['uid_class'],
						'publishtime'=>$t,
						'checkuserid'=>$res['uid_class'],
						'checktime'=>$t,
						'isdelete'=>0,
						'tag'=>$res['tag'],
						'isvideo'=>1,
						'groupid'=>$groupid,
					);
					//print_r($data);echo '<br />';
					//print_r(date('Y-m-d H:i',$t));echo '<br />';
					if($data['title']){
						if(strlen($res['intro'])>30){
							$data['title']=substr($res['intro'],0,30);
							$data['title'].='...';
						}else{
							$data['title']=$res['intro'];
						}
					}else{
						$data['title']=date('Y-m-d H:i',$t);
					}
					
					if ($p['photo_set']!='') {
						$data['photosetid']=$p['photo_set'];
					}
					//print_r($data);exit;
					$result1 = $this->_dbAdapter->insert ( 'article', $data );
					$articleid = $this->_dbAdapter->lastInsertId (); //获得刚插入的活动id
					if($articleid){
						$data1=array('articlekey'=>$articleid);
						$result2 = $this->_dbAdapter->update ( 'article', $data1,'groupid='.$groupid.' and articleid ='.$articleid);
					
						$result3 = $this->_dbAdapter->update ( 'article_files', $data1,'groupid='.$groupid.' and articlefilesid ='.$value);
						
						$data2=array(
							'class_uid'=>$res['uid_class'],
							'credit'=>$credit_artice_photo,
							'credit_type'=>'photo',
							'credit_date'=>date('Y-m-d',$t),
							'addtime'=>$t,
							'isminus'=>0,
							'filename'=>$res['cloudfilename'],
							'ischecked'=>1,
						);
						$result=$this->_dbAdapter->insert('credit_logs',$data2);
						$isoked=0;
						foreach($stu_name as $key3=>$value3){
							$data3=array(
								'articlekey'=>$articleid,
								'studentid'=>$value3,
								'groupid'=>$groupid
							);
							$result4 = $this->_dbAdapter->insert ( 'article_student', $data3);
							if($result4){
								$isoked=1;
							}
						}
						
						if($isoked){
							//插入推送
								$student_post=implode(',',$stu_name);
								$this->push_message('article',0,0,$student_post,1,0);
					
								$sql='select schoolid,classid from class where groupid='.$groupid.' and uid='.$res['uid_class'];
								$classinfo = $this->_dbAdapter->fetchRow($sql);
								$this->_dbAdapter->query("call pro_feed_notify(".$classinfo['schoolid'].",".$classinfo['classid'].",'article',".$res['uid_class'].",".$articleid.",1,'".$student_post."')");
					
							
							$isok_publish++;
						}
					}
					
				}
			}
			
/*********************************************************************/			

			if ($isok_publish || $isok_del || $isok_work) {
				
				$this->feedback ( '审核发布通过'.$isok_publish.'个视频,删除'.$isok_del.'个视频,'.$isok_work.'个视频加入作品集', '成功', '/'.$this->controller.'/check/groupid/'.$groupid.'/schoolid/'.$schoolid.'/uploaddate/'.$uploaddate, 'tip', 0 );
			} else {
				throw new Exception ( '操作失败,或已经删除，请先刷新查看！' );//操作失败,或已经删除，请先刷新查看！
			}
		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), 'note', 'javascript:window.history.back();', 'warning' );
		}
	}
	
	/*
	检索发布视频的列表
	*/
	public function publishAction(){
		try {
			$this->view->groupid=$groupid = ( int ) $this->_request->getParam ( 'groupid' );

			if(!$groupid){
				throw new Exception ( '参数错误' );
			}

			//机构信息
			$sql="SELECT * FROM `groups` where groupid=".$groupid;
			$result = $this->_dbAdapter->fetchRow ($sql);
			$this->view->group = $result;
			if(!$result)
				throw new Exception ( 'groupid错误' );
			
			$this->view->uid_class = $uid_class = ( int ) $this->_request->getParam ( 'uid_class' );
			//print_r();exit;
			
			if(!$uid_class){
				$sql="select uid_class,schoolid,classname,COUNT(articlefilesid) as number from article_files_class_v where groupid=".$groupid." and isdelete=0 and ischecked=1 and fext='mp4' and (articlekey='' or articlekey is NULL) group by uid_class";
				$school_class_picture=$this->_dbAdapter->fetchAssoc($sql); 
				$this->view->school_class_picture=$school_class_picture;
//echo $sql;exit;
				if($school_class_picture){
					//显示校区列表
					$schoollist=array();
					foreach($school_class_picture as $key => $value){
						if(!in_array($value['schoolid'],$schoollist))
							$schoollist[]=$value['schoolid'];
					}
					$sql="SELECT  schoolid,schoolname FROM school where groupid=".$groupid." and schoolid in (".implode(',',$schoollist).")";
					$school=$this->_dbAdapter->fetchAssoc ( $sql );
					$this->view->school= $school; 
				}
			}
			
			//获取图片列表
			if($uid_class){
				//print_r($uid_class);exit;
				//获取照片分类设置
				$sql='SELECT value FROM `setting` where variable="photo_set"';
				$result=$this->_dbAdapter ->fetchOne ( $sql );
				$result=Zend_Json::decode($result);
				$photo_set=array();
				$photo_set=explode(',',$result);
				//print_r($photo_set);exit;
				$this->view->photo_set=$photo_set;
				
				//取班级名
				$sql='select a.classname,a.schoolid,a.classid,b.schoolname from class a left join school b on a.schoolid=b.schoolid and a.groupid=b.groupid where a.groupid='.$groupid.' and a.uid='.$uid_class;
				$classinfo=$this->_dbAdapter->fetchRow ( $sql );
				if(!$classinfo)
					throw new Exception ( '班级参数错误' );
				
				$this->view->classname=$classinfo['classname'];
				$this->view->schoolname=$classinfo['schoolname'];

				//获取该班日志日期列表	
				$sql="select from_unixtime(uploadtime,'%Y-%m-%d') as uploaddate,count(*) as num from article_files_class_v where groupid=".$groupid." and uid_class=".$uid_class." and isdelete=0 and fext='mp4' and ischecked=1 and (articlekey='' or articlekey is NULL) group by from_unixtime(uploadtime,'%Y-%m-%d') order by uploadtime desc ";
				$uploaddatelist=$this->_dbAdapter->fetchPairs($sql); 
				$this->view->uploaddatelist=$uploaddatelist;
				//print_r($uploaddatelist);exit;
				//选取班级图片
				if($uploaddatelist){
					$uploaddate=$this->_request->getParam ( 'uploaddate' );
					$uploadkeys=array_keys($uploaddatelist);
					
					if(!$uploaddate || !in_array($uploaddate,$uploadkeys) )
						$uploaddate=current($uploadkeys);
					$this->view->uploaddate=$uploaddate;
					//print_r($uploaddate);exit;	
					$sql="select articlefilesid,articlekey,concat('http://',cloudhost,cloudpath,cloudfilename,'.',fext) as avatar,intro,uid_class,memberlist,schoolid,classname,from_unixtime(uploadtime,'%Y-%m-%d %H:%i') as uploadtimeDisp from article_files_class_v where groupid=".$groupid." and uid_class=".$uid_class." and isdelete=0 and fext='mp4' and ischecked=1 and (articlekey='' or articlekey is NULL) and from_unixtime(uploadtime,'%Y-%m-%d')='".$uploaddate."'  ORDER BY uploadtime asc";
					//echo $sql;exit;
					$picturelist_tmp=$this->_dbAdapter->fetchAll($sql); 
					//print_r($picturelist_tmp);exit;
					
					//取班级学生
					$sql='select studentid,cnname,concat("http://",filehost,filepath,filename,".",fext) as filename from group_student_class_parents_v  where ismainid=1 and groupid='.$groupid.' and uid='.$uid_class;
					$studentlist=$this->_dbAdapter->fetchAssoc ( $sql );
					$this->view->student= $studentlist; 
					//print_r($studentlist);exit;
					
					$picturelist=array();
					foreach($picturelist_tmp as $key=>$value){
						$arr=explode(',',$value['memberlist']);
						sort($arr);
						$arr_key=implode('_',$arr);

						if(!isset($picturelist[$arr_key])){
						$studentnamelist=array();
						foreach($arr as $k=>$v){
							$studentnamelist[]=$studentlist[$v]['cnname'];
							$picturelist[$arr_key]['studentinfo'][$v]=$studentlist[$v];
						}
						
						$picturelist[$arr_key]['student']=implode(',',$studentnamelist);
						$picturelist[$arr_key]['studentlist']=$arr;
						}
						
						if($value['intro']){
							$value['intro']=stripslashes($value['intro']);
						}
						$picturelist[$arr_key]['piclist'][]=$value;
					}
					unset($picturelist_tmp);
				$this->view->picturelist=$picturelist;
				//print_r($picturelist);exit;
				}
			}
		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), 'note', 'javascript:window.history.back();', 'warning' );
		}
	}

	public function publishshowvideoAction(){
		try {
			$groupid = ( int ) $this->_request->getParam ( 'groupid' );
			$articlefilesid = $this->_request->getParam ( 'articlefilesid' );
			$uid_class = $this->_request->getParam ( 'uid_class' );
			//print_r($groupid);echo '<br />';print_r($schoolid);echo '<br />';print_r($articlefilesid);exit;

	     	if (! $groupid)
				throw new Exception ( '参数错误！' );
	     	if (! $articlefilesid)
				throw new Exception ( '参数错误！' );
	     	if (! $uid_class)
				throw new Exception ( '参数错误！' );
			$this->view->groupid=$groupid;
			$this->view->uid_class=$uid_class;
						
			if($uid_class){
				$sql="select concat('http://',cloudhost,cloudpath,cloudfilename,'.',fext) as avatar,intro from article_files where groupid=".$groupid." and articlefilesid='".$articlefilesid."'";
			    $picturelist=$this->_dbAdapter->fetchRow($sql); 
				$this->view->picturelist=$picturelist;
				//print_r($picturelist);exit;
			}
		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), 'note', 'javascript:window.history.back();', 'warning' );
		}
	}
	
	public function deleteshowvideoAction(){
		try {
			$groupid = ( int ) $this->_request->getParam ( 'groupid' );
			$articlefilesid = $this->_request->getParam ( 'articlefilesid' );
			$schoolid = $this->_request->getParam ( 'schoolid' );
			//print_r($groupid);echo '<br />';print_r($schoolid);echo '<br />';print_r($articlefilesid);exit;

	     	if (! $groupid)
				throw new Exception ( '参数错误！' );
	     	if (! $articlefilesid)
				throw new Exception ( '参数错误！' );
	     	if (! $schoolid)
				throw new Exception ( '参数错误！' );
			$this->view->groupid=$groupid;
			$this->view->schoolid=$schoolid;
						
			if($schoolid){
				$sql="select concat('http://',cloudhost,cloudpath,cloudfilename,'.',fext) as avatar,intro from article_files where articlefilesid='".$articlefilesid."'";
			    $picturelist=$this->_dbAdapter->fetchRow($sql); 
				$this->view->picturelist=$picturelist;
				//print_r($picturelist);exit;
			}
		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), 'note', 'javascript:window.history.back();', 'warning' );
		}
	}
	
	public function fastpublishdeleteAction(){
		try {
			if (! $this->isPost ()) {
				throw new Exception ( '参数错误' );
			}
			$p =$this->_request->getPost ();
			//print_r($p);exit;

			$schoolid=$p['schoolid'];
			$uid_class=$p['uid_class'];
			$groupid=$p['groupid'];
			$page=$p['page'];
/*			$sql="SELECT * FROM `groups` where groupid=".$groupid;
			$result = $this->_dbAdapter->fetchRow ($sql);
			
			if($groupid)
				$this->_dbAdapter=$this->getDbLink($groupid);
*/
			foreach($p['htmlid'] as $key=>$value){
				$sql='update article_files set isdelete=1 where articlefilesid='.$value;
				$result1 = $this->_dbAdapter->query($sql);
				
				$sql='update article_files set ischecked=0 where articlefilesid='.$value;
				$result = $this->_dbAdapter->query($sql);
			}
			//printf($result);exit;
			if ($result) {
				$this->feedback ( '成功', '成功', '/'.$this->controller.'/publish/groupid/'.$groupid.'/schoolid/'.$schoolid.'/uid_class/'.$uid_class.'/page/'.$page , 'tip', 0 );
			} else {
				throw new Exception ( '操作失败,或已经删除，请先刷新查看！' );//操作失败,或已经删除，请先刷新查看！
			}


		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), 'note', 'javascript:window.history.back();', 'warning' );
		}
	}
	
	public function choosedeleteAction(){
		try {
			if (! $this->isPost ()) {
				throw new Exception ( '参数错误' );
			}
			$p =$this->_request->getPost ();

			$schoolid=$p['sid'];
			$page=$p['pagenum'];
			$groupid=$p['pid'];
/*			$sql="SELECT * FROM `groups` where groupid=".$groupid;
			$result = $this->_dbAdapter->fetchRow ($sql);
			
			if($groupid)
				$this->_dbAdapter=$this->getDbLink($groupid);
*/			
			foreach($p['htmlid'] as $key=>$value){
				$sql='update article_files set isdelete=1 where articlefilesid='.$value;
				//echo $sql;exit;
				$result = $this->_dbAdapter->query($sql);
			}
			if ($result) {
				$this->feedback ( '成功', '成功', '/'.$this->controller.'/check/groupid/'.$groupid.'/schoolid/'.$schoolid.'/page/'.$page , 'tip', 0 );
			} else {
				throw new Exception ( '操作失败,或已经删除，请先刷新查看！' );//操作失败,或已经删除，请先刷新查看！
			}
		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), 'note', 'javascript:window.history.back();', 'warning' );
		}
	}
	
	public function picdeleteAction(){
		try {
			$aid = $this->_request->getParam ( 'aid' );
			$page = $this->_request->getParam ( 'page' );
			$schoolid = $this->_request->getParam ( 'schoolid' );
			if(!$aid)
				throw new Exception ( '参数错误' );
			
			$groupid = ( int ) $this->_request->getParam ( 'groupid' );

	     	if (! $groupid)
				throw new Exception ( '参数错误！' );
			$this->view->groupid=$groupid;
			
/*			$sql="SELECT * FROM `groups` where groupid=".$groupid;
			$result = $this->_dbAdapter->fetchRow ($sql);
*/
			$sql='update article_files set isdelete=1 where articlefilesid='.$aid;
			$result = $this->_dbAdapter->query($sql);

			if ($result) {
				$this->feedback ( '成功', '成功', '/'.$this->controller.'/check/groupid/'.$groupid.'/schoolid/'.$schoolid.'/page/'.$page , 'tip', 0 );
			} else {
				throw new Exception ( '操作失败,或已经删除，请先刷新查看！' );//操作失败,或已经删除，请先刷新查看！
			}
		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), 'note', 'javascript:window.history.back();', 'warning' );
		}
	}

/*
删除图片列表
*/
	public function deleteAction(){
		try {
			
			$groupid = ( int ) $this->_request->getParam ( 'groupid' );
	     	if (! $groupid)
				throw new Exception ( '参数错误！' );
			$this->view->groupid=$groupid;
			
			$sql="SELECT * FROM `groups` where groupid=".$groupid;
			$result = $this->_dbAdapter->fetchRow ($sql);

			//取集团校区
			$sql="SELECT schoolid,schoolname FROM school where groupid=".$groupid." order by schoolid asc ";
			$school=$this->_dbAdapter->fetchAssoc ( $sql );
			$this->view->school= $school; 
			
			$schoolid = ( int ) $this->_request->getParam ( 'schoolid' );
			$this->view->schoolid=$schoolid;
			
			if($schoolid){
				$count = 60;
				$curpage = ( int ) $this->_request->getParam ( 'page' );
				
				if (! $curpage)
						$curpage = 1;
					$offset = ($curpage - 1) * $count; 
					
				$sql="select SQL_CALC_FOUND_ROWS articlefilesid,articlekey,concat('http://',cloudhost,cloudpath,cloudfilename,'.',fext) as avatar,intro,uid_class,memberlist,schoolid,classname,from_unixtime(uploadtime,'%Y-%m-%d %H:%i') as uploadtimeDisp from article_files_class_v where groupid=".$groupid." and schoolid=".$schoolid." and isdelete=1 and fext='mp4' ORDER BY uploadtimeDisp desc limit $offset,$count ";
				//echo $sql;exit;
			    $picturelist=$this->_dbAdapter->fetchAll($sql); 
				
				foreach($picturelist as $key=>$value){
					$picturelist[$key]['memberlist']=explode(',',$value['memberlist']);
				}
				$this->view->picturelist=$picturelist;
				
				$param ['file'] = '/' . $this->controller . '/' . $this->action;
				$param ['totalnum'] = $this->_dbAdapter->fetchOne ( 'SELECT FOUND_ROWS()' ); 
				$param ['perpagenum'] = $count; // 每页显示的数目
				$param ['disnum'] = 11; // 取单数显示，当前页停在中间
				$param ['curpage'] = $curpage; // 当前页码
				$this->view->allnum=$param ['totalnum'];
				$this->view->pagenum=$param ['curpage'];
				
				$page = new MyClass_Page ( $param );
				$page->setvar ( array ('groupid' => $groupid,'schoolid' => $schoolid) );
				$this->view->page= $page->getNumPage (); 			
			}			
		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), 'note', 'javascript:window.history.back();', 'warning' );
		}
	}

	public function recoverAction(){
		try {
			if (! $this->isPost ()) {
				throw new Exception ( 'parameter_error' );
			}
			$p =$this->_request->getPost ();
			//print_r($p);exit;
			$schoolid=$p['sid'];
			$page=$p['pagenum'];
			$groupid=$p['pid'];
/*			$sql="SELECT * FROM `groups` where groupid=".$groupid;
			$result = $this->_dbAdapter->fetchRow ($sql);
			
			if($groupid)
				$this->_dbAdapter=$this->getDbLink($groupid);
			
*/			foreach($p['htmlid'] as $key=>$value){
				$sql='update article_files set isdelete=0 and ischecked=0 where groupid='.$groupid.' and articlefilesid='.$value;
				$result = $this->_dbAdapter->query($sql);
			}
			if ($result) {
				$this->feedback ( '成功', '成功', '/'.$this->controller.'/delete/groupid/'.$groupid.'/schoolid/'.$schoolid.'/page/'.$page , 'tip', 0 );
			} else {
				throw new Exception ( '操作失败,或已经删除，请先刷新查看！' );//操作失败,或已经删除，请先刷新查看！
			}
		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), 'note', 'javascript:window.history.back();', 'warning' );
		}
	}
	
	public function deleteabsoluteAction(){
		try {
			if (! $this->isPost ()) {
				throw new Exception ( 'parameter_error' );
			}
			$p =$this->_request->getPost ();
			//print_r($p);exit;

			$schoolid=$p['sid'];
			$page=$p['pagenum'];
			$groupid=$p['pid'];
/*			$sql="SELECT * FROM `groups` where groupid=".$groupid;
			$result = $this->_dbAdapter->fetchRow ($sql);
			
			if($groupid)
				$this->_dbAdapter=$this->getDbLink($groupid);
*/

			foreach($p['htmlid'] as $key=>$value){
				$sql='delete  from article_files where articlefilesid='.$value;
				$result = $this->_dbAdapter->query($sql);
			}
			//printf($result);exit;
			if ($result) {
				$this->feedback ( '成功', '成功', '/'.$this->controller.'/delete/groupid/'.$groupid.'/schoolid/'.$schoolid.'/page/'.$page , 'tip', 0 );
			} else {
				throw new Exception ( '操作失败,或已经删除，请先刷新查看！' );//操作失败,或已经删除，请先刷新查看！
			}
		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), 'note', 'javascript:window.history.back();', 'warning' );
		}
	}
	
	/*
	日志发布的处理程序
	*/
	private  function publishArticle($groupid=0,$uid_class=0,$title='',$content='',$memberlist=array(),$piclist=array(),$phototypeid='') {
		try {
		if(!$groupid || !$uid_class || empty($memberlist) || empty($piclist) )
			return 0;
		
			$sql="SELECT * FROM `groups` where groupid=".$groupid;
			$result = $this->_dbAdapter->fetchRow ($sql);
			if(!$result)
				return -1;
				
/*			if($groupid && !$this->_dbAdapter)
				$this->_dbAdapter=$this->getDbLink($groupid);
*/
			$sql='select * from article_files where articlefilesid in ('.implode(',',$piclist).')';
			$articlefileslist = $this->_dbAdapter->fetchAssoc($sql);
			if(!$articlefileslist)
				return -2;
				
			$content=strip_tags(trim($content));	
			$content=addslashes($content);
			
			$title=strip_tags(trim($title));	
			$title=addslashes($title);

			$addtime=0;
			$intro=array();
			foreach($articlefileslist as $key => $value){
				if($addtime<$value['uploadtime'])
					$addtime=$value['uploadtime'];
				if(empty($title) && !empty($value['intro']) && $content != $value['intro']){
					$value['intro']=strip_tags(trim($value['intro']));	
					$value['intro']=addslashes($value['intro']);
					if(!in_array($value['intro'],$intro))	
						$intro[]=$value['intro'];
				}
			}
			if($intro){
				$content=implode(' ',$intro);
			}
			
			if($title=='' && !empty($content)){
				$title=substr($content,0,30).'...';
			}elseif($title=='' && $content==''){
				$title=date('Y-m-d H:i',$addtime);
			}

			$data=array(
				'content'=>$content,
				'createteacherid'=>$uid_class,
				'classid'=>$uid_class,
				'title'=>$title,
				'addtime'=>$addtime,
				'publishteacherid'=>$uid_class,
				'publishtime'=>$addtime,
				'checkuserid'=>$uid_class,
				'checktime'=>$addtime,
				'isdelete'=>0,
				'photosetid'=>$phototypeid,
				'groupid'=>$groupid
			);
			
			$result = $this->_dbAdapter->insert ( 'article', $data );
			$articleid = $this->_dbAdapter->lastInsertId (); //获得刚插入的活动id
			if(!$articleid){
				return -3;
			}
			$result = $this->_dbAdapter->update ( 'article', array('articlekey'=>$articleid),'articleid='.$articleid);
			$result = $this->_dbAdapter->update ( 'article_files', array('articlekey'=>$articleid),'articlefilesid in('.implode(',',$piclist).')');

			//插入学生表
			foreach($memberlist as $key=>$value){
				$data=array(
					'articlekey'=>$articleid,
					'studentid'=>$value,
					'groupid'=>$groupid
				);
				$result =$this->_dbAdapter->insert ( 'article_student', $data);
			}

			//增加积分
			//取采用照片积分标准
			$sql="SELECT value FROM `setting` where variable='credit_artice_photo'";
			$credit_artice_photo = $this->_dbAdapter->fetchOne ($sql);
			if(!$credit_artice_photo)
				$credit_artice_photo=0;
			
			foreach($articlefileslist as $key => $value){		
				$data=array(
						'class_uid'=>$uid_class,
						'credit'=>$credit_artice_photo,
						'credit_type'=>'photo',
						'credit_date'=>date('Y-m-d',$addtime),
						'addtime'=>$addtime,
						'isminus'=>0,
						'filename'=>$filename,
						'ischecked'=>1,
					);
				$result=$this->_dbAdapter->insert('credit_logs',$data);
			}
			
			return 1;
		} catch ( Exception $e ) {
			return $e->getMessage ();
		}
	}

	public function fastpublishAction(){
		try {
			if (! $this->isPost ()) {
				throw new Exception ( '参数错误' );
			}
			$p =$this->_request->getPost ();

			if (count($p['htmlid'])>9) {
				throw new Exception ( '图片不能超过9张' );
			}

			if (!isset($p['htmlid']) || !is_array($p['htmlid']) || count($p['htmlid'])==0) {
				throw new Exception ( '先选择图片然后才能发布日志' );
			}

			 $titlelen=$this->utf8_strlen($p['title']);

			 if($titlelen>60){ 
				  throw new Exception ( '标题最多只能60个字符！' ); 
			 }
			  			 
			 $contentlen=$this->utf8_strlen($p['content']);
			 if($contentlen>1000 ){ 
			 	  throw new Exception ( '内容最多只能1000个字符！' ); 
			 }
			
			
			$groupid=$p['groupid']; 
			$uid_class=$p['uid_class'];
			$schoolid=$p['schoolid'];
			$uploaddate=$p['uploaddate'];

/*			$sql="SELECT * FROM `groups` where groupid=".$groupid;
			$result = $this->_dbAdapter->fetchRow ($sql);
*/			
			//取采用照片积分标准
			$sql="SELECT value FROM `setting` where variable='credit_artice_photo'";
			$credit_artice_photo = $this->_dbAdapter->fetchOne ($sql);


/*			if($groupid && !$this->_dbAdapter)
				$this->_dbAdapter=$this->getDbLink($groupid);
*/
			//取班级学生
			$sql='select studentid,cnname from group_student_class_parents_v  where ismainid=1 and groupid='.$groupid.' and uid_class='.$p['uid_class'];
			$student=$this->_dbAdapter->fetchPairs ( $sql );
			$this->view->student= $student; 
			
			//取发送对象
			$stu_name=array();
			foreach($p['htmlid'] as $key=>$value){
				$sql='select * from article_files where articlefilesid='.$value;
				$res = $this->_dbAdapter->fetchRow($sql);
				
				if($res['memberlist']<>0){
					$studentlist=explode(',',$res['memberlist']);
				}
				//print_r($studentlist);echo '<br />';
				foreach($studentlist as $key1=>$value1){
					if(!in_array($value1,$stu_name)){
						$stu_name[]=$value1;
					}else{
						continue;
					}
				}
				//print_r($stu_name);exit;
			}
			$sql='select uploadtime from article_files where articlefilesid='.$p['htmlid'][0];
			$t=$this->_dbAdapter->fetchOne($sql);
			$p['content']=strip_tags($p['content']);	
			$p['content']=addslashes($p['content']);
			$p['title']=strip_tags($p['title']);	
			$p['title']=addslashes($p['title']);
			
			$data=array(
				'content'=>$p['content'],
				'createteacherid'=>$p['uid_class'],
				'classid'=>$p['uid_class'],
				'title'=>$p['title'],
				'addtime'=>$t,
				'publishteacherid'=>$p['uid_class'],
				'publishtime'=>$t,
				'checkuserid'=>$p['uid_class'],
				'checktime'=>$t,
				'isdelete'=>0,
				'groupid'=>$groupid
			);
			//print_r(date('Y-m-d H:i',$t));echo '<br />';
			if($data['title']==''){
				$data['title']=substr($p['content'],0,30);
				if($data['title']){
					$data['title'].='...';
				}
			}
			if($data['title']==''){
				$data['title']=date('Y-m-d H:i',$t);
			}
			
			if ($p['photo_set']!='') {
				$data['photosetid']=$p['photo_set'];
			}
			//print_r($data);exit;
			$result1 = $this->_dbAdapter->insert ( 'article', $data );
			$articleid = $this->_dbAdapter->lastInsertId (); //获得刚插入的活动id
			if($articleid){
				$data1=array('articlekey'=>$articleid);
				$result2 = $this->_dbAdapter->update ( 'article', $data1,'articleid ='.$articleid);
				
				foreach($p['htmlid'] as $key2=>$value2){
					$data2=array('articlekey'=>$articleid);
					$result3 = $this->_dbAdapter->update ( 'article_files', $data2,'articlefilesid ='.$value2);
					
					$sql="select cloudfilename from article_files where articlefilesid='".$value2."'";
					$filename=$this->_dbAdapter->fetchOne($sql);
					
					$data=array(
						'class_uid'=>$p['uid_class'],
						'credit'=>$credit_artice_photo,
						'credit_type'=>'photo',
						'credit_date'=>$t,
						'addtime'=>$t,
						'isminus'=>0,
						'filename'=>$filename,
						'ischecked'=>1,
					);
					$result=$this->_dbAdapter->insert('credit_logs',$data);
				}
				foreach($stu_name as $key3=>$value3){
					$data3=array(
						'articlekey'=>$articleid,
						'studentid'=>$value3,
						'groupid'=>$groupid
					);
					$result4 = $this->_dbAdapter->insert ( 'article_student', $data3);
				}
			}
			
			if ($result4) {
				$this->_redirect ( '/'.$this->controller.'/publish/groupid/'.$groupid.'/schoolid/'.$schoolid.'/uid_class/'.$uid_class.'/uploaddate/'.$uploaddate );
			} else {
				throw new Exception ( '操作失败,或已经删除，请先刷新查看！' );//操作失败,或已经删除，请先刷新查看！
			}
			
		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), 'note', 'javascript:window.history.back();', 'warning' );
		}
	}



	public function growupAction(){
		try {
			if (! $this->isPost ()) {
				throw new Exception ( 'parameter_error' );
			}
			$p =$this->_request->getPost ();
			//print_r($p);exit;
			
			$groupid=$p['pid']; 
			$schoolid=$p['sid'];
			$page=$p['pagenum'];
/*			$sql="SELECT * FROM `groups` where groupid=".$groupid;
			$result = $this->_dbAdapter->fetchRow ($sql);
	
			if($groupid && !$this->_dbAdapter)
				$this->_dbAdapter=$this->getDbLink($groupid);
*/			
			//标记为作品集
			foreach($p['htmlid'] as $key=>$value){
				$sql="update article_files set mark=1 where articlefilesid ='".$value."'";
				//echo $sql;exit;
				$res = $this->_dbAdapter->query($sql);
			}
			
			if ($res) {
				$this->feedback ( '成功', '成功', '/'.$this->controller.'/check/groupid/'.$groupid.'/schoolid/'.$schoolid.'/page/'.$page , 'tip', 0 );
			} else {
				throw new Exception ( '操作失败,或已经删除，请先刷新查看！' );//操作失败,或已经删除，请先刷新查看！
			}
			
		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), 'note', 'javascript:window.history.back();', 'warning' );
		}
	}

	public function seegrowupAction(){
		try {
			$groupid = ( int ) $this->_request->getParam ( 'groupid' );
	     	if (! $groupid)
				throw new Exception ( '参数错误！' );
			$this->view->groupid=$groupid;
			$schoolid = ( int ) $this->_request->getParam ( 'schoolid' );
			$this->view->schoolid=$schoolid;
			
			$sql="SELECT * FROM `groups` where groupid=".$groupid;
			$result = $this->_dbAdapter->fetchRow ($sql);
			
			//取集团校区
			$sql="SELECT schoolid,schoolname FROM school where groupid=".$groupid." order by schoolid asc ";
			$school=$this->_dbAdapter->fetchAssoc ( $sql );
			$this->view->school= $school; 
			
			$schoolid = ( int ) $this->_request->getParam ( 'schoolid' );
			$this->view->schoolid=$schoolid;
			
			if($schoolid){
				$count = 20;
				$curpage = ( int ) $this->_request->getParam ( 'page' );
				if (! $curpage)
						$curpage = 1;
					$offset = ($curpage - 1) * $count; 
					
				$sql="select SQL_CALC_FOUND_ROWS articlefilesid,articlekey,concat('http://',cloudhost,cloudpath,cloudfilename,'.',fext) as avatar,intro,uid_class,memberlist,schoolid,classname,from_unixtime(uploadtime,'%Y-%m-%d %H:%i') as uploadtimeDisp from article_files_class_v where groupid=".$groupid." and schoolid=".$schoolid." and isdelete=0 and fext='mp4' and mark=1 ORDER BY uploadtimeDisp desc limit $offset,$count ";
				//echo $sql;exit;
			    $picturelist=$this->_dbAdapter->fetchAll($sql); 
				
				foreach($picturelist as $key=>$value){
					$picturelist[$key]['memberlist']=explode(',',$value['memberlist']);
				}
				$this->view->picturelist=$picturelist;
				//print_r($picturelist);exit;
				
				$param ['file'] = '/' . $this->controller . '/' . $this->action;
				$param ['totalnum'] = $this->_dbAdapter->fetchOne ( 'SELECT FOUND_ROWS()' ); 
				$param ['perpagenum'] = $count; // 每页显示的数目
				$param ['disnum'] = 11; // 取单数显示，当前页停在中间
				$param ['curpage'] = $curpage; // 当前页码
				$this->view->allnum=$param ['totalnum'];
				$this->view->pagenum=$param ['curpage'];
				
				$page = new MyClass_Page ( $param );
				$page->setvar ( array ('groupid' => $groupid,'schoolid' => $schoolid) );
				$this->view->page= $page->getNumPage (); 
			}
		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), 'note', 'javascript:window.history.back();', 'warning' );
		}
	}
	
	public function growupdeletesomeAction(){
		try {
			if (! $this->isPost ()) {
				throw new Exception ( '参数错误' );
			}
			$p =$this->_request->getPost ();
			//print_r($p);exit;
			
			$groupid=$p['pid']; 
			$schoolid=$p['sid'];
			$page=$p['pagenum'];
/*			$sql="SELECT * FROM `groups` where groupid=".$groupid;
			$result = $this->_dbAdapter->fetchRow ($sql);
			
			if($groupid && !$this->_dbAdapter)
				$this->_dbAdapter=$this->getDbLink($groupid);
*/
			//取消标记为作品集
			foreach($p['htmlid'] as $key=>$value){
				$sql="update article_files set mark=0 where articlefilesid ='".$value."'";
				//echo $sql;exit;
				$res = $this->_dbAdapter->query($sql);
			}
			
			if ($res) {
				$this->feedback ( '成功', '成功', '/'.$this->controller.'/seegrowup/groupid/'.$groupid.'/schoolid/'.$schoolid.'/page/'.$page , 'tip', 0 );
			} else {
				throw new Exception ( '操作失败,或已经删除，请先刷新查看！' );//操作失败,或已经删除，请先刷新查看！
			}
			
		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), 'note', 'javascript:window.history.back();', 'warning' );
		}
	}
	
	public function growupdeleteAction(){
		try {
			$aid = $this->_request->getParam ( 'aid' );
			$page = $this->_request->getParam ( 'page' );
			$schoolid = $this->_request->getParam ( 'schoolid' );
			if(!$aid)
				throw new Exception ( '参数错误' );
			
			$groupid = ( int ) $this->_request->getParam ( 'groupid' );
			//print_r($groupid);exit;
	     	if (! $groupid)
				throw new Exception ( '参数错误！' );
			$this->view->groupid=$groupid;
			
			//$sql="SELECT * FROM `groups` where groupid=".$groupid;
			//$result = $this->_dbAdapter->fetchRow ($sql);

			$sql='update article_files set mark=0 where articlefilesid='.$aid;
			//echo $sql;exit;
			$result = $this->_dbAdapter->query($sql);
			//printf($result);exit;
			if ($result) {
				$this->feedback ( '成功', '成功', '/'.$this->controller.'/seegrowup/groupid/'.$groupid.'/schoolid/'.$schoolid.'/page/'.$page , 'tip', 0 );
			} else {
				throw new Exception ( '操作失败,或已经删除，请先刷新查看！' );//操作失败,或已经删除，请先刷新查看！
			}
		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), 'note', 'javascript:window.history.back();', 'warning' );
		}
	}
	
	
	public function picdeleteabsAction(){
		try {
			$aid = $this->_request->getParam ( 'aid' );
			$page = $this->_request->getParam ( 'page' );
			$schoolid = $this->_request->getParam ( 'schoolid' );
			if(!$aid)
				throw new Exception ( '参数错误' );
			
			$groupid = ( int ) $this->_request->getParam ( 'groupid' );
			//print_r($groupid);exit;
	     	if (! $groupid)
				throw new Exception ( '参数错误！' );
			$this->view->groupid=$groupid;
			
			$sql='delete from article_files where articlefilesid='.$aid;
			//echo $sql;exit;
			$result = $this->_dbAdapter->query($sql);
			//printf($result);exit;
			if ($result) {
				$this->feedback ( '成功', '成功', '/'.$this->controller.'/delete/groupid/'.$groupid.'/schoolid/'.$schoolid.'/page/'.$page , 'tip', 0 );
			} else {
				throw new Exception ( '操作失败,或已经删除，请先刷新查看！' );//操作失败,或已经删除，请先刷新查看！
			}
		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), 'note', 'javascript:window.history.back();', 'warning' );
		}
	}

	/*
	一键审核本页全部
	*/
	public function oppublishallAction(){
		try {
			$groupid = intval($this->_request->getParam ( 'groupid' ));
			$uid_class = intval($this->_request->getParam ( 'uid_class' ));
			$uploaddate = $this->_request->getParam ( 'uploaddate' );
			$a=strtotime($uploaddate);
			if(!$a || !$groupid || !$uid_class)
				throw new Exception ( '参数错误' );
			
			$sql="select articlefilesid,articlekey,intro,memberlist from article_files_class_v where groupid=".$groupid." and uid_class=".$uid_class." and isdelete=0 and ischecked=1 and fext<>'mp4' and articlekey='' and from_unixtime(uploadtime,'%Y-%m-%d')='".$uploaddate."'  ORDER BY uploadtime asc";
			$picturelist_tmp=$this->_dbAdapter->fetchAll($sql); 

			$picturelist=array();
			foreach($picturelist_tmp as $key=>$value){
						
						$arr=explode(',',$value['memberlist']);
						sort($arr);
						$arr_key=implode(',',$arr);
						$picturelist[$arr_key][]=$value['articlefilesid'];
						
			}
			unset($picturelist_tmp);
					
			$a=array();
			
			foreach($picturelist as $key => $value){
							//$piclist=implode(',',$value);
							$memberlist=explode(',',$key);
							$picnum=count($value);
							$piclist_tmp=array();
							
							for($i=0;$i<$picnum; $i++){
								$piclist_tmp[]=$value[$i];
								if(count($piclist_tmp)>=9){
								//	print_r($piclist_tmp);
									$a[]= $this->publishArticle($groupid,$uid_class,'','',$memberlist,$piclist_tmp);
									$piclist_tmp=array();
								}
							}
							if(!empty($piclist_tmp))
								$a[]= $this->publishArticle($groupid,$uid_class,'','',$memberlist,$piclist_tmp);
			}
			//print_r($a);exit;
			$this->_redirect ( '/'.$this->controller.'/publish/groupid/'.$groupid.'/schoolid/'.$schoolid.'/uid_class/'.$uid_class.'/uploaddate/'.$uploaddate );

			} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), 'note', 'javascript:window.history.back();', 'warning' );
		}
	}

	public function pubpicdeleteAction(){
		try {
			$aid = $this->_request->getParam ( 'aid' );
			$page = $this->_request->getParam ( 'page' );
			$schoolid = $this->_request->getParam ( 'schoolid' );
			$uid_class = $this->_request->getParam ( 'uid_class' );
			if(!$aid)
				throw new Exception ( '参数错误' );
			
			$groupid = ( int ) $this->_request->getParam ( 'groupid' );
			//print_r($groupid);exit;
	     	if (! $groupid)
				throw new Exception ( '参数错误！' );
			$this->view->groupid=$groupid;
			/*
			$sql="SELECT * FROM `groups` where groupid=".$groupid;
			$result = $this->_dbAdapter->fetchRow ($sql);
			
			//连接运营库
			$dbArray=array();
			$dbArray['host']=$result['dbhost'];
			$dbArray['username']=$result['dbusername'];
			$dbArray['password']=$this->authcode($result['dbpassword'], 'DECODE', 'mactop') ;
			$dbArray['dbname']=$result['dbname'];
			
			$dbAdapter = Zend_Db::factory ("PDO_MYSQL", $dbArray );
			Zend_Registry::set('dbAdapter', $dbAdapter);

			$dbAdapter=Zend_Registry::get('dbAdapter');
			$dbAdapter->query ( 'set names utf8');	
			*/
			$sql='update article_files set isdelete=1 where articlefilesid='.$aid;
			$result1 = $this->_dbAdapter->query($sql);
			
			$sql='update article_files set ischecked=0 where articlefilesid='.$aid;
			$result2 = $this->_dbAdapter->query($sql);
			//printf($result);exit;
			if ($result2) {
				$this->feedback ( '成功', '成功', '/'.$this->controller.'/publish/groupid/'.$groupid.'/schoolid/'.$schoolid.'/uid_class/'.$uid_class.'/page/'.$page , 'tip', 0 );
			} else {
				throw new Exception ( '操作失败,或已经删除，请先刷新查看！' );//操作失败,或已经删除，请先刷新查看！
			}
		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), 'note', 'javascript:window.history.back();', 'warning' );
		}
	}


	public function deletearticleAction(){
		try {
			$articleid = $this->_request->getParam ( 'adid' );
			$page = $this->_request->getParam ( 'page' );
			$schoolid = $this->_request->getParam ( 'sid' );
			$uid_class = $this->_request->getParam ( 'cid' );
			$groupid = $this->_request->getParam ( 'groupid' );
			if(!$articleid)
				throw new Exception ( '参数错误' );
			
	     	if (! $groupid)
				throw new Exception ( '参数错误！' );
			/*
			$sql="SELECT * FROM `groups` where groupid=".$groupid;
			$result = $this->_dbAdapter->fetchRow ($sql);
			//print_r($result);exit;
			//连接运营库
			$dbArray=array();
			$dbArray['host']=$result['dbhost'];
			$dbArray['username']=$result['dbusername'];
			$dbArray['password']=$this->authcode($result['dbpassword'], 'DECODE', 'mactop') ;
			$dbArray['dbname']=$result['dbname'];
			
			$dbAdapter = Zend_Db::factory ("PDO_MYSQL", $dbArray );
			Zend_Registry::set('dbAdapter', $dbAdapter);

			$dbAdapter=Zend_Registry::get('dbAdapter');
			$dbAdapter->query ( 'set names utf8');	
			*/
			
			if($articleid){
				$sql1='update article set isdelete=1 where articleid='.$articleid;
				
				$result1 = $this->_dbAdapter->query($sql1);
				//print_r($this->_dbAdapter);exit;
				$sql='select articlekey from article where articleid='.$articleid;
				$articlekey = $this->_dbAdapter->fetchOne($sql);
				

				$sql="select cloudfilename from article_files where articlekey='".$articlekey."'";
				$filename = $this->_dbAdapter->fetchCol($sql);
				//print_r($filename);exit;
				foreach($filename as $key=>$value){
					$sql="select filename from credit_logs where filename='".$value."'";
					$res=$this->_dbAdapter->fetchOne($sql);
					if($res){
						$sql1="delete from credit_logs where filename='".$value."'";
						$result = $this->_dbAdapter->query($sql1);
					}
				}
				
				$sql2="update article_files set articlekey='' where articlekey='".$articlekey."'";
				$result2 = $this->_dbAdapter->query($sql2);
				
				$sql3="update article_student set isdelete=1 where articlekey='".$articlekey."'";
				$result3 = $this->_dbAdapter->query($sql3);


				
			}
			if ($result3) {
				$this->feedback ( '成功', '成功', '/'.$this->controller.'/articlelist/groupid/'.$groupid.'/schoolid/'.$schoolid.'/uid_class/'.$uid_class.'/page/'.$page , 'tip', 0 );
			} else {
				throw new Exception ( '操作失败,或已经删除，请先刷新查看！' );//操作失败,或已经删除，请先刷新查看！
			}
		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), 'note', 'javascript:window.history.back();', 'warning' );
		}
	}


	public function editarticleAction(){
		try {
			$articleid = $this->_request->getParam ( 'adid' );
			$page = $this->_request->getParam ( 'page' );
			$schoolid = $this->_request->getParam ( 'sid' );
			$uid_class = $this->_request->getParam ( 'cid' );
			$groupid = $this->_request->getParam ( 'groupid' );
			if(!$articleid)
				throw new Exception ( '参数错误' );
			
	     	if (! $groupid)
				throw new Exception ( '参数错误！' );
			
			$sql='SELECT value FROM `setting` where variable="photo_set"';
			$result=$this->_dbAdapter ->fetchOne ( $sql );
			$result=Zend_Json::decode($result);
			$photo_set=array();
			$photo_set=explode(',',$result);
			//print_r($photo_set);exit;
			$this->view->photo_set=$photo_set;
			$this->view->schoolid=$schoolid;
			$this->view->uid_class=$uid_class;
			$this->view->groupid=$groupid;
			$this->view->page=$page;

			/*
			$sql="SELECT * FROM `groups` where groupid=".$groupid;
			$result = $this->_dbAdapter->fetchRow ($sql);
			//print_r($result);exit;
			//连接运营库
			$dbArray=array();
			$dbArray['host']=$result['dbhost'];
			$dbArray['username']=$result['dbusername'];
			$dbArray['password']=$this->authcode($result['dbpassword'], 'DECODE', 'mactop') ;
			$dbArray['dbname']=$result['dbname'];
			
			$dbAdapter = Zend_Db::factory ("PDO_MYSQL", $dbArray );
			Zend_Registry::set('dbAdapter', $dbAdapter);

			$dbAdapter=Zend_Registry::get('dbAdapter');
			$dbAdapter->query ( 'set names utf8');	
			*/
			if($articleid){
				$sql1='select * from article where articleid='.$articleid;
				$result1 = $this->_dbAdapter->fetchRow($sql1);
				//print_r($result1);echo '<br />';
				$sql="select concat('http://',cloudhost,cloudpath,cloudfilename,'.',fext) as avatar from article_files where articlekey='.$articleid.'";
				
				$sql="select concat('http://',cloudhost,cloudpath,cloudfilename,'.',fext) as avatar from article_files where articlekey=".$articleid;
				$filename = $this->_dbAdapter->fetchCol($sql);
				//print_r($filename);exit;
			}
         
		 $this->view->result= $result1;
		 $this->view->filename= $filename;
		 
		 
		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), 'note', 'javascript:window.history.back();', 'warning' );
		}
	}


	public function opeditAction(){
		try {
			if (! $this->isPost ()) {
				throw new Exception ( '参数错误' );
			}
			$p =$this->_request->getPost ();
			//print_r($p);echo '<br />';

			 $titlelen=$this->utf8_strlen($p['title']);
			 if($titlelen>60){ 
				  throw new Exception ( '标题最多只能60个字符！' ); 
			 }
			  			 
			 $contentlen=$this->utf8_strlen($p['content']);
			 if($contentlen>1000 ){ 
			 	  throw new Exception ( '内容最多只能1000个字符！' ); 
			 }
			$p['content']=strip_tags($p['content']);	
			$p['content']=addslashes($p['content']);
			$p['title']=strip_tags($p['title']);	
			$p['title']=addslashes($p['title']);
			
			
			$groupid=$p['groupid']; 
			$uid_class=$p['uid_class'];
			$schoolid=$p['schoolid'];
			/*
			if($groupid && !$this->_dbAdapter)
				$this->_dbAdapter=$this->getDbLink($groupid);
				
			
			
			$sql="SELECT * FROM `groups` where groupid=".$groupid;
			$result = $this->_dbAdapter->fetchRow ($sql);

			//连接运营库
			$dbArray=array();
			$dbArray['host']=$result['dbhost'];
			$dbArray['username']=$result['dbusername'];
			$dbArray['password']=$this->authcode($result['dbpassword'], 'DECODE', 'mactop') ;
			$dbArray['dbname']=$result['dbname'];
			
			$dbAdapter = Zend_Db::factory ("PDO_MYSQL", $dbArray );
			Zend_Registry::set('dbAdapter', $dbAdapter);

			$dbAdapter=Zend_Registry::get('dbAdapter');
			$dbAdapter->query ( 'set names utf8');	
			
			*/
			
			$data=array(
				'content'=>$p['content'],
				'title'=>$p['title'],
			);
			//print_r(date('Y-m-d H:i',$t));echo '<br />';
			if($data['title']==''){
				$data['title']=substr($p['content'],0,30);
				if($data['title']){
					$data['title'].='...';
				}
			}
			
			if ($p['photo_set']!='') {
				$data['photosetid']=$p['photo_set'];
			}
			
			if($p['articleid']){
				$result1 = $this->_dbAdapter->update ( 'article', $data,'articleid ='.$p['articleid']);
			}
			if ($result1) {
				$this->feedback ( '成功', '成功', '/'.$this->controller.'/editarticle/groupid/'.$groupid.'/sid/'.$schoolid.'/cid/'.$uid_class.'/adid/'.$p['articleid'] , 'tip', 3 );
			} else {
				throw new Exception ( '保存失败' );//操作失败,或已经删除，请先刷新查看！
			}
			
		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), 'note', 'javascript:window.history.back();', 'warning' );
		}
	}


	 
//查看详细统计
	public function statisticsAction(){
		try {
			$this->view->groupid=$groupid = ( int ) $this->_request->getParam ( 'groupid' );
			if(!$groupid){
				//跳转到机构列表
				throw new Exception ( '参数错误' );
			}
/*
			$sql="SELECT * FROM `groups` where groupid=".$groupid;
			$result = $this->_dbAdapter->fetchRow ($sql);
			
			//连接运营库
			$dbArray=array();
			$dbArray['host']=$result['dbhost'];
			$dbArray['username']=$result['dbusername'];
			$dbArray['password']=$this->authcode($result['dbpassword'], 'DECODE', 'mactop') ;
			$dbArray['dbname']=$result['dbname'];
			
			$dbAdapter = Zend_Db::factory ("PDO_MYSQL", $dbArray );
			Zend_Registry::set('dbAdapter', $dbAdapter);

			$dbAdapter=Zend_Registry::get('dbAdapter');
			$dbAdapter->query ( 'set names utf8');			
			*/
			$this->view->schoolid = $schoolid = ( int ) $this->_request->getParam ( 'schoolid' );
			if(!$schoolid){
				//显示校区列表
				$count = 40;
				$curpage = ( int ) $this->_request->getParam ( 'page' );
				
				if (! $curpage)
						$curpage = 1;
					$offset = ($curpage - 1) * $count; 

				//取集团校区
				$sql="SELECT SQL_CALC_FOUND_ROWS schoolid,schoolname FROM school where groupid=".$groupid." order by schoolid asc limit $offset,$count ";
				$school=$this->_dbAdapter->fetchAssoc ( $sql );
				$this->view->school= $school; 

				$param ['file'] = '/' . $this->controller . '/' . $this->action;
				$param ['totalnum'] = $this->_dbAdapter->fetchOne ( 'SELECT FOUND_ROWS()' ); 
				$param ['perpagenum'] = $count; // 每页显示的数目
				$param ['disnum'] = 11; // 取单数显示，当前页停在中间
				$param ['curpage'] = $curpage; // 当前页码
				$this->view->allnum=$param ['totalnum'];
				$this->view->pagenum=$param ['curpage'];
				
				$page = new MyClass_Page ( $param );
				$page->setvar ( array ('groupid' => $groupid) );
				$this->view->page= $page->getNumPage (); 
				//结束
			}else{
				//取学校名
				$sql='select schoolname from school where groupid='.$groupid.' and schoolid='.$schoolid;
				$this->view->schoolname=$this->_dbAdapter->fetchOne ( $sql );

				//显示班级列表
				$sql="SELECT uid,classname FROM class where groupid='.$groupid.' and schoolid=".$schoolid." order by uid asc ";
				$class=$this->_dbAdapter->fetchAssoc ( $sql );
				$this->view->class=$class;
			}
			$uid_class = ( int ) $this->_request->getParam ( 'uid_class' );
			$this->view->uid_class = $uid_class;
			//获取数据
			if($uid_class){
				//取班级名
				$this->view->classname=$class[$uid_class]['classname'];
			   
			   //本班级学员列表
			   $sql="select studentid,cnname from group_student_class_parents_v where ismainid=1 and groupid=".$groupid." and uid_class=".$uid_class;
			   $student=$this->_dbAdapter->fetchAssoc($sql);
		       
			   if(!$student)
					 throw new Exception ( '本班学生列表为空' );  
					  
			    foreach($student as $key => $value){
					$student[$key]['articleNum']=0;
					$student[$key]['imgNum']=0;
			    } 	
			    //print_r($student);exit;
				//获取天传入的变量
				$start_date = $this->_request->getParam ( 'start_date' ); 
				$end_date =  $this->_request->getParam ( 'end_date' );
			    
				$now_date=date('Y-m-d');
				if(strtotime($start_date)<=0 || strtotime($start_date) > strtotime($now_date))
					$start_date=$now_date;
					
				if(!strtotime($end_date) || $end_date>$now_date)
					$end_date=$now_date;
				
				if($start_date>$end_date)
					$end_date=$start_date;

				$this->view->start_date=$start_date;
				$this->view->end_date=$end_date;

				//获取时间段的所有文章
				$sql='SELECT articlekey FROM `article` where groupid='.$groupid.' and isdelete=0 and classid='.$uid_class.' and  from_unixtime(publishtime,"%Y-%m-%d")>="'.$start_date.'" and from_unixtime(publishtime,"%Y-%m-%d")<="'.$end_date.'" ';
				//echo $sql;echo '<br />';
				$articlekeylist=$this->_dbAdapter->fetchCol($sql);
				$articlekeylist=implode('","',$articlekeylist);
				
				$sql='SELECT studentid,articlekey from article_student WHERE articlekey in ("'.$articlekeylist.'")';
				$studentArticlekey=$this->_dbAdapter->fetchAll($sql);
				
				if($articlekeylist){
					//获取这些文章包含的图片数
					$sql='SELECT articlekey,COUNT(cloudfilename) as num from article_files where articlekey in ("'.$articlekeylist.'") GROUP BY articlekey';
					$imgcount=$this->_dbAdapter->fetchPairs($sql);
					//print_r($imgcount);echo '<br />';exit;
					//按学员列表获取所有学员统计
/*					foreach($articlekeylist as $key2=>$value2){
						$sql='SELECT studentid,articlekey from article_student WHERE articlekey = "'.$value2.'"';
						//echo $sql;exit;
						$studentArticlekey=$dbAdapter->fetchAssoc($sql);
						//print_r($studentArticlekey);echo '<br />';
						foreach($student as $key => $value){
						   foreach($studentArticlekey as $key1=> $value1){
							   //print_r($imgcount[$value1['articlekey']]);
							   if($value1['studentid']==$value['studentid']){
								 $student[$key]['articleNum']++;
								 if(isset($imgcount[$value1['articlekey']]))
									$student[$key]['imgNum'] +=$imgcount[$value1['articlekey']];
							   }
						  }
					   }
					}   
*/			   
					foreach($student as $key => $value){
					   foreach($studentArticlekey as $key1=> $value1){
						   //print_r($imgcount[$value1['articlekey']]);
						   if($value1['studentid']==$value['studentid']){
							 $student[$key]['articleNum']++;
							 if(isset($imgcount[$value1['articlekey']]))
								$student[$key]['imgNum'] +=$imgcount[$value1['articlekey']];
						   }
					  }
				   }
				   
				}
			    //print_r($student); exit;
				$this->view->student=$student;
				$this->view->studentcount=count($student);
			}
			
		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), 'note', 'javascript:window.history.back();', 'warning' );
		}
	}

	 
//查看学校统计
	public function statisticsallAction(){
		try {
			$this->view->groupid=$groupid = ( int ) $this->_request->getParam ( 'groupid' );
			if(!$groupid){
				//跳转到机构列表
				throw new Exception ( '参数错误' );
			}
			/*
			$sql="SELECT * FROM `groups` where groupid=".$groupid;
			$result = $this->_dbAdapter->fetchRow ($sql);
			//连接运营库
			$dbArray=array();
			$dbArray['host']=$result['dbhost'];
			$dbArray['username']=$result['dbusername'];
			$dbArray['password']=$this->authcode($result['dbpassword'], 'DECODE', 'mactop') ;
			$dbArray['dbname']=$result['dbname'];
			
			$dbAdapter = Zend_Db::factory ("PDO_MYSQL", $dbArray );
			Zend_Registry::set('dbAdapter', $dbAdapter);

			$dbAdapter=Zend_Registry::get('dbAdapter');
			$dbAdapter->query ( 'set names utf8');			
			*/
			//显示校区列表
			$sql="SELECT schoolid,schoolname FROM school where groupid=".$groupid." order by schoolid asc";
			$school=$this->_dbAdapter->fetchPairs ( $sql );
			$this->view->school= $school; 
			//print_r($school);
		    //获取每个校区学生数
		    $sql="select schoolid,count(studentid) as num from student where groupid=".$groupid." group by schoolid";
		    $student=$this->_dbAdapter->fetchPairs($sql);
		    //print_r($student);
			
			//获取天传入的变量
			$start_date = $this->_request->getParam ( 'start_date' ); 
			$end_date =  $this->_request->getParam ( 'end_date' );
			
			$now_date=date('Y-m-d');
			if(strtotime($start_date)<=0 || strtotime($start_date) > strtotime($now_date))
				$start_date=$now_date;
				
			if(!strtotime($end_date) || $end_date>$now_date)
				$end_date=$now_date;
			
			if($start_date>$end_date)
				$end_date=$start_date;

			$this->view->start_date=$start_date;
			$this->view->end_date=$end_date;

			//获取每个校区发布的图片数
		    $sql='SELECT schoolid,COUNT(articlefilesid) as num FROM `article_files_class_v` where groupid='.$groupid.' and isdelete=0 and ischecked=1 and from_unixtime(uploadtime,"%Y-%m-%d")>="'.$start_date.'" and from_unixtime(uploadtime,"%Y-%m-%d")<="'.$end_date.'" GROUP BY schoolid';
			$picture=$this->_dbAdapter->fetchPairs($sql);
			//print_r($picture);exit;
			$this->view->picture=$picture;
			$this->view->school=$school;
			$this->view->student=$student;
			
		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), 'note', 'javascript:window.history.back();', 'warning' );
		}
	}


//查看班级统计
	public function statisclassAction(){
		try {
			$this->view->groupid=$groupid = ( int ) $this->_request->getParam ( 'groupid' );
			$this->view->schoolid=$schoolid = ( int ) $this->_request->getParam ( 'schoolid' );
			if(!$groupid){
				//跳转到机构列表
				throw new Exception ( '参数错误' );
			}
			/*
			$sql="SELECT * FROM `groups` where groupid=".$groupid;
			$result = $this->_dbAdapter->fetchRow ($sql);
			//连接运营库
			$dbArray=array();
			$dbArray['host']=$result['dbhost'];
			$dbArray['username']=$result['dbusername'];
			$dbArray['password']=$this->authcode($result['dbpassword'], 'DECODE', 'mactop') ;
			$dbArray['dbname']=$result['dbname'];
			
			$dbAdapter = Zend_Db::factory ("PDO_MYSQL", $dbArray );
			Zend_Registry::set('dbAdapter', $dbAdapter);

			$dbAdapter=Zend_Registry::get('dbAdapter');
			$dbAdapter->query ( 'set names utf8');			
			*/			
			//获取该校区班级
			$sql="select uid,classname from class where groupid=".$groupid." and isdel=0 and schoolid=".$schoolid;
			$class=$this->_dbAdapter->fetchPairs($sql);
			//print_r($class);
		    //获取每个校区学生数
		    $sql="select class_uid,count(studentid) as num from student where groupid=".$groupid." and schoolid=".$schoolid." group by class_uid";
		    $student=$this->_dbAdapter->fetchPairs($sql);
			//print_r($student);
			//获取天传入的变量
			$start_date = $this->_request->getParam ( 'start_date' ); 
			$end_date =  $this->_request->getParam ( 'end_date' );
			
			$now_date=date('Y-m-d');
			if(strtotime($start_date)<=0 || strtotime($start_date) > strtotime($now_date))
				$start_date=$now_date;
				
			if(!strtotime($end_date) || $end_date>$now_date)
				$end_date=$now_date;
			
			if($start_date>$end_date)
				$end_date=$start_date;

			$this->view->start_date=$start_date;
			$this->view->end_date=$end_date;

			//获取每个校区发布的图片数
		    $sql='SELECT uid_class,COUNT(articlefilesid) as num FROM `article_files_class_v` where groupid='.$groupid.' and isdelete=0 and ischecked=1 and from_unixtime(uploadtime,"%Y-%m-%d")>="'.$start_date.'" and from_unixtime(uploadtime,"%Y-%m-%d")<="'.$end_date.'" and schoolid='.$schoolid.' GROUP BY uid_class';
			$picture=$this->_dbAdapter->fetchPairs($sql);
			//print_r($picture);exit;
			$this->view->picture=$picture;
			$this->view->class=$class;
			$this->view->student=$student;
			
		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), 'note', 'javascript:window.history.back();', 'warning' );
		}
	}


//查看统计
	public function onlinestatisticsAction(){
		try {
			$this->view->groupid=$groupid = ( int ) $this->_request->getParam ( 'groupid' );
			if(!$groupid){
				//跳转到机构列表
				throw new Exception ( '参数错误' );
			}
/*
			$sql="SELECT * FROM `groups` where groupid=".$groupid;
			$result = $this->_dbAdapter->fetchRow ($sql);
			
			//连接运营库
			$dbArray=array();
			$dbArray['host']=$result['dbhost'];
			$dbArray['username']=$result['dbusername'];
			$dbArray['password']=$this->authcode($result['dbpassword'], 'DECODE', 'mactop') ;
			$dbArray['dbname']=$result['dbname'];
			
			$dbAdapter = Zend_Db::factory ("PDO_MYSQL", $dbArray );
			Zend_Registry::set('dbAdapter', $dbAdapter);

			$dbAdapter=Zend_Registry::get('dbAdapter');
			$dbAdapter->query ( 'set names utf8');			
			*/
			//取集团校区
			$sql="SELECT SQL_CALC_FOUND_ROWS schoolid,schoolname FROM school where groupid=".$groupid." order by schoolid asc";
			$school=$this->_dbAdapter->fetchAssoc ( $sql );

			//统计班级数
			$sql="SELECT uid,classname,schoolid FROM class where groupid=".$groupid."  ORDER BY schoolid asc";
			$class=$this->_dbAdapter->fetchAll ( $sql );
			//print_r($class);echo '<br />';
			foreach($class as $key=>$value){
				if($value['schoolid']){
					$school[$value['schoolid']]['class'][$value['uid']]=$value['classname'];
				}
			}


			//获取天传入的变量
			$start_date = $this->_request->getParam ( 'start_date' ); 
			$end_date =  $this->_request->getParam ( 'end_date' );
			
			$now_date=date('Y-m-d');
			if(strtotime($start_date)<=0 || strtotime($start_date) > strtotime($now_date))
				$start_date=$now_date;
				
			if(!strtotime($end_date) || $end_date>$now_date)
				$end_date=$now_date;
			
			if($start_date>$end_date)
				$end_date=$start_date;

			$this->view->start_date=$start_date;
			$this->view->end_date=$end_date;

			//获取时间段的上线班级数
			foreach($school as $key=>$value){
				$sql='SELECT uid_class FROM `article_files` where uid_class in ( SELECT uid from class WHERE groupid='.$groupid.' and schoolid='.$value['schoolid'].') and  from_unixtime(uploadtime,"%Y-%m-%d")>="'.$start_date.'" and from_unixtime(uploadtime,"%Y-%m-%d")<="'.$end_date.'"  GROUP BY uid_class';			
				$school[$value['schoolid']]['onlineclass']=$this->_dbAdapter->fetchCol($sql);
				$school[$value['schoolid']]['lv']=0;
				if($school[$value['schoolid']]['class'] && $school[$value['schoolid']]['onlineclass']){
					$school[$value['schoolid']]['lv']=round(count($school[$value['schoolid']]['onlineclass'])/count($school[$value['schoolid']]['class'])*100,2);
					$school[$value['schoolid']]['lv'].='%';
				}
			}
			//print_r($school);exit;
			$this->view->school=$school;
			
		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), 'note', 'javascript:window.history.back();', 'warning' );
		}
	}


	 private  function utf8_strlen($string = null) {
		// 将字符串分解为单元
		preg_match_all("/./us", $string, $match);
		// 返回单元个数
		return count($match[0]);
	}
	 
	 //以下内容保持不变
	public function noRouteAction() {
		$this->_redirect ( '/' );
	}
	
	public function __call($method, $args) {
		if ('Action' == substr ( $method, - 6 )) {
			$url = '/' . $this->controller . '/index';
			return $this->_redirect ( $url );
		}
		throw new Exception ( 'Invalid method' );
	}
}

